<template>
  <div>
    <FilterTable ref="table" :columns="columns" :fetchapi="fetchApi" :params="fetchParams" :datakey="'rows'" :isSelectColumn="false" :onColumnsChange="columns => (this.columns = columns)" />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { getComplaintInfo, getRepairHistoryInfo } from '@/api/customerRepair/customerCareCTI';
import {  getWxlxSelect } from '@/api/repair/repairReception/customer';

export default {
  name: '',
  mixins: [dictionary],
  props: {
    phone: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      fetchApi: getRepairHistoryInfo,
      // fetchParams: { phone:this.phone ,xhrAbort: false },
      fetchParams: this.phone ? { phone: this.phone } : { xhrAbort: true },
      columns: this.createColumns()
    };
  },
  mounted() {
    this.getWxlxSelect();
  },
  methods: {
    createColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO',
          minWidth: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE',
          minWidth: 100,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: 'VIN',
          dataIndex: 'VIN',
          minWidth: 150,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
            title: '维修类型',
            dataIndex: 'REPAIR_TYPE_CODE',
            width: 100,
            sorter: true,
            editable: false,
            editType: 'select',
            editItems: []
        },
        {
          title: '进厂里程',
          dataIndex: 'IN_MILEAGE',
          minWidth: 100,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户名称',
          dataIndex: 'OWNER_NAME',
          minWidth: 100,
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '客户电话',
          dataIndex: 'MOBILE',
          minWidth: 100,
          sorter: true,
          filter: true,
          filterType: 'input'
        }
      ];
    },
     // 获取维修项目类型
    async getWxlxSelect() {
      const res = await getWxlxSelect();
      // console.log('维修项目==============维修类型' + res);
      this.columns.find(x => x.dataIndex === 'REPAIR_TYPE_CODE').editItems = res.data.map(x => ({ text: x.REPAIR_TYPE_NAME, value: x.REPAIR_TYPE_CODE + '' }));
    }
  }
};
</script>
